module.exports = function getPublicIP() {
    const os = require("os");
    const ifaces = os.networkInterfaces();
    let en0;

    Object.keys(ifaces).forEach((ifname) => {
        let alias = 0;

        ifaces[ifname].forEach(function (iface) {
            if ("IPv4" !== iface.family || iface.internal !== false) {
                // skip over internal (i.e. 127.0.0.1) and non-ipv4 addresses
                return;
            }

            if (alias >= 1) {
                // this single interface has multiple ipv4 addresses
                en0 = iface.address;
                console.log(ifname + ":" + alias, iface.address);
            } else {
                // this interface has only one ipv4 adress
                console.log(ifname, iface.address);
                en0 = iface.address;
            }
            ++alias;
        });
    });
    return en0;
}

